<?php
defined('_JEXEC') or die('Restricted access'); 
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');
JHTML::_('behavior.modal');	
$user = &JFactory::getUser();
?>

<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/swfobject.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.uploadify.v2.1.4.min.js"></script>
<style>
	#backgroundfile{
		width:160px;
		text-align: center;
	}
	#imagefile{
		text-align:left;
	}
	.image_prview {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    float: left;
	    margin: 2px;
	    padding: 5px;
	    text-align: center;
	    width: 160px;
	}
</style>

<script type="text/javascript">
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'apply_sub_point' || pressbutton == 'save_sub_point' ) {
			var item_total = 0 ;			
 			<?php 
				$i = 1 ;	
 				foreach ($this->point as $item){ 
 					if($item->point > 0){
	 					if($i == 1){
							$flag = $item->id ;
						}
			?>
						var item_point<?php echo $item->id ; ?> = <?php echo $item->point ; ?> ;
						var sub_point<?php echo $item->id ; ?> = parseInt(document.adminForm.p<?php echo $item->id ; ?>.value) ;
						if((item_point<?php echo $item->id ; ?> < sub_point<?php echo $item->id ; ?>) && ! isNaN(sub_point<?php echo $item->id ; ?>)){
							alert('Error !') ;
							document.adminForm.p<?php echo $item->id ; ?>.focus();
							return false ;
						}else if(! isNaN(sub_point<?php echo $item->id ; ?>)){
							item_total = item_total + sub_point<?php echo $item->id ; ?> ;
						}
			<?php 
					$i++ ;
					}
				}
			?>
				if(item_total != <?php echo $this->redemption->point ; ?>){
					alert('Ponts are not match. Please preview agains') ;
					document.adminForm.p<?php echo $flag ; ?>.focus() ;
					return false ;
				}
			
			submitform( pressbutton );
		}
	}
 </script>
<form id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >
	<div class="col width-100">
		<fieldset class="adminform">
			<legend><?php echo JText::_('Redemption Manager')?></legend>
				<table width="100%">
					 <tr>
					 	<td><b>Transaction Id</b></td>	
					 	<td><b>Outlet</b></td>
					 	<td><b>Type</b></td>			
					 	<td><b>Points</b></td>	
					 	<td width="150">&nbsp;</td>	
					 </tr>
					 <?php if(count($this->point) > 0): ?>
						 <?php foreach ($this->point as $item): ?>
						 	<?php if($item->point > 0 ): ?>
							 	<tr>
							 		<td><?php echo empty($item->transaction)? 0 : $item->transaction ; ?></td>	
							 		<td>
							 		<?php 
							 			if(!empty($this->t_outlet[$item->transaction])){
							 				echo $this->t_outlet[$item->transaction] ;
							 			}
						 			?>
							 		</td>
								 	<td>
									 	<?php 
									 		$i_type = $item->type ; 
									 		switch($i_type){
									 			case 0 : 
									 				echo "transaction" ;
									 				break;
								 				case 1 : 
													echo "registration"	;	 				
									 				break;
									 			case 2 : 
									 				echo "add point by hand" ;
									 				break;
								 				case 3 : 
									 				echo "banner click" ;
									 				break;
									 		}
									 	?>
								 	</td>			
								 	<td><?php echo $item->point ; ?></td>
								 	<td>
								 		<input style="float: right ;" type="text" name="p<?php echo $item->id ; ?>" id="p<?php echo $item->id ; ?>" value="" class="" />
								 	</td>			
							 	</tr>
						 	<?php endif ; ?>
						 <?php endforeach; ?>
					 <?php endif; ?>
					 <tr>
					 	<td colspan="4" align="right">Total</td>
					 	<td align="right" style="padding-right: 10px;"><b style = "color: #FF0000; font-size:15px; font-weight:bold ;"><?php echo $this->redemption->point ;?></b></td>
					 </tr>
				</table>
		</fieldset>
	</div>
	<script type="text/javascript">
		
	</script>
	<input type="hidden" name="controller" value="profile" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->user_info->user_id ; ?>" />
	<input type="hidden" name="mid" value="<?php echo (int)$this->user_info->id ; ?>" />
	<input type="hidden" name="rid" value="<?php echo $this->redemption->id ; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>